<?php
class DataStream{
    static function Read($data){
        return explode('c', $data);
    }
    static function ConvertToBuffer($data){
        $size = 0;
        $_d = explode('c', trim($data));
        foreach($_d as $s){
           $size+=intval(DataStream::SplitSize('-', $s)); 
        }
        $buf= ByteBuffer::allocate( $size ) ;
        foreach($_d as $s){
           $z=intval(DataStream::SplitSize('-', $s));           
           switch ($z){
                case 1:
                   DataUtil::writeInt8( $buf ,  DataStream::SplitData('-', $s) ) ;
                 break;
                case 2:
                   DataUtil::writeInt16( $buf ,  DataStream::SplitData('-', $s) ) ;
                 break;
                case 4:
                   DataUtil::writeInt32( $buf ,  DataStream::SplitData('-', $s) ) ;
                 break; 
           }
        }
        return $buf->_array();
    }
    static function SplitSize($c ,$s){
        $r = explode($c, trim($s));
        return intval(trim($r[0]));
    }
    static function SplitData($c ,$s){
        $r = explode($c, trim($s));
        return intval(trim($r[1]));
    }
}
?>